/*
 * @Author: qjb 
 *  更新信息查看js
 * @Date: 2020-01-77  
 */
layui.config({
}).use(['zlConfig', 'zlContext', 'element'], function (exports) {
    var $ = layui.$
        , zlContext = layui.zlContext
        , zlConfig = layui.zlConfig
        , statusName = zlConfig.global.result.statusName
        , msgName = zlConfig.global.result.msgName
        , OK = zlConfig.global.result.okState
        , element = layui.element;

    zlContext.post(layui.cache['contentPath'] + '/manager/version/queryssxt', {}, function (result) {
        if (result[statusName] == OK) {
            var datas = result.obj;
            if (datas && datas.length > 0) {
                zlContext.headerAjax(layui.cache['contentPath'] + '/manager/coredictionary/querymxtree', 'post', { 'ZDZ_DICTIONARYID': '1C630186B5FF40E2959E4B09CA2D0BFC' }, function (result1) {
                    if (result1[statusName] == OK) {
                        var dcdatas = result1.obj;
                        var map = {};
                        for (var index = 0; index < dcdatas.length; index++) {
                            if (dcdatas[index].ZDZ_ZIDZ) {
                                map[dcdatas[index].ZDZ_MINGC] = dcdatas[index].ZDZ_ZIDZ
                            }
                        }
                        bulidTab(datas, map);
                    }
                    else {
                        zlContext.errorMsg(result1[msgName]);
                    }
                });

            }
        }
        else {
            zlContext.errorMsg(result[msgName]);
        }
    });
    function bulidTab(datas, map) {
        var $parent = $('.layui-tab-title'),
            html = '';
        for (var index = 0; index < datas.length; index++) {
            if (map[datas[index]]) {
                html += "<li key='" + datas[index] + "'>" + map[datas[index]] + "</li>";
            } else {
                html += "<li key='" + datas[index] + "'>" + datas[index] + "</li>";
            }

        }
        $parent.append(html);

    }
    function getdatas(params) {
        zlContext.post(layui.cache['contentPath'] + '/manager/version/querybycondition', params, function (result) {
            if (result[statusName] == OK) {
                var datas = result.obj;
                if (datas && datas.length > 0) {
                    bulidTimeLine(datas);
                }
            }
            else {
                zlContext.errorMsg(result[msgName]);
            }
        });
    }
    getdatas({ "VER_SUOSXT": "CORE" });


    function bulidTimeLine(datas) {
        $('.layui-show').removeClass('layui-show');
        var $parent = $('.layui-tab-content'),
            html = '<div class="layui-tab-item layui-show"> <ul class="layui-timeline">';
        for (var index = 0; index < datas.length; index++) {
            var content = datas[index].VER_MIAOS;
            if (content && content.indexOf('\n操作系统') > -1) {
                content = content.substr(0, content.indexOf('\n操作系统'));
                if (content) {
                    content = content.replace(/[\n\r]/g, '<br>  ');
                }
            }
            html += '<li class="layui-timeline-item">';
            html += '<i class="layui-icon layui-timeline-axis">&#xe63f;</i>';
            html += '<div class="layui-timeline-content layui-text">';
            html += '<h3 class="layui-timeline-title">' + datas[index].VER_BANB + '<span class="layui-badge-rim">' + datas[index].VER_GENGXSJ + '</span></h3>'
            html += '<p>' + content + '</p>';
            html += '</div>';
            html += '</li>';
        }
        html += "</ul>";
        html += "</div>";
        $parent.append(html);
    }
    element.on('tab(project)', function (data) {
        if ($(this).attr('isload') != 1) {
            var text = $(this).attr('key');
            getdatas({ "VER_SUOSXT": text });
            $(this).attr('isload', 1);
        }

    });
});

